<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 深拷贝拷贝多层, 每一级别的数据都会拷贝.
        var obj = {
            id: 1,
            name: 'andy',
            msg: {
                age: 18
            },
            color: ['pink', 'red']
        };
        var o = {};
        const deepCopy = (newObj,oldObj) =>{
            for(k in oldObj){
                 // 判断我们的属性值属于那种数据类型
                // 1. 获取属性值  oldobj[k]
                let item = oldObj[k];
                //先判断是否等于数组
                if(item instanceof Array){
                    newObj[k] = [];
                    deepCopy(newObj[k],item)
                }else if(item instanceof Object){
                    newObj[k] = {};
                    deepCopy(newObj[k],item)
                }else{
                    // 4. 属于简单数据类型
                    newObj[k] = item;
                }
            }
        }
        deepCopy(o,obj);
        console.log(o);
    </script>
</body>
</html>